<template>
  <zm-dialog
    title="下载附件"
    :visible.sync="value"
    append-to-body
    :before-close="dialogClose"
    :close-on-click-modal="false"
    size="small"
    class="select-export-style"
  >
    <div class="pd20">
      <el-radio-group v-model="type" size="small" class="db select-type">
        <div class="db" v-for="(item, index) in typeList" :key="index">
          <el-radio :label="item.value" class="df-center mb20">
            <div class="type-item df-center">
              <div class="flex-one">
                <div class="fs20">{{ item.label }}</div>
              </div>
            </div>
          </el-radio>
        </div>
      </el-radio-group>
    </div>
    <div slot="footer" class="tr">
      <el-button @click="dialogClose">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </zm-dialog>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin'
import { downloadFile } from '@/api/src/returnedPlan'
export default {
  components: { },
  mixins: [dialogMixin],
  props: {
    params: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      type: '1'
    }
  },
  computed: {
    typeList () {
      return [
        {
          label: '导出合同相关附件',
          value: '1'
        },
        {
          label: '导出回执单相关附件',
          value: '2'
        }
      ]
    },
    saleOrderTypeArr () {
      return this.params.saleOrderType.split(',').filter(e => e)
    }
  },
  created () {},
  methods: {
    async submit () {
      // 下载接口
      console.log(this.saleOrderTypeArr, 'this.paramsthis.paramsthis.params')
      if (this.type === '2' && !(this.saleOrderTypeArr.includes('1') || this.saleOrderTypeArr.includes('2'))) {
        this.$message.warning('该选项的销售类型应该为日常销售单/特批销售单')
        return
      }
      let params = {
        ids: this.params.orderId,
        type: this.type
      }
      // 获取下载链接
      const res = await downloadFile(params)
      const a = document.createElement('a')
      a.setAttribute('download', '')
      a.setAttribute('href', res.url)
      a.click()
    }
  }
}
</script>
<style lang="scss">
.select-export-style {
  .select-type {
    .el-radio__label {
      flex: 1;
    }
    .type-icon {
      font-size: 40px;
    }
  }
  .type-item {
    width: 600px;
    padding: 20px;
    border: 1px solid #dedede;
  }
}
</style>
